import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/domain/home/home_data_dto.dart';
import 'package:bxultimate/resources/assets.dart';
import 'package:bxultimate/widgets/app/app_title.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class AppTaskListItem extends StatefulWidget {
  final Task task;

  const AppTaskListItem({super.key, required this.task});

  @override
  State<AppTaskListItem> createState() => _AppTaskListItemState();
}

class _AppTaskListItemState extends State<AppTaskListItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
      ),
      clipBehavior: Clip.antiAlias,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _buildTaskLeft(),
          Gaps.hGap8,
          Expanded(child: _buildTaskRight()),
        ],
      ),
    );
  }

  Widget _buildTaskLeft() {
    return Container(
      width: 110,
      height: 140,
      decoration: BoxDecoration(
          gradient: const LinearGradient(
        begin: Alignment.topLeft,
        end: Alignment.bottomRight,
        colors: [Color(0xFFFFBB95), Color(0xFFFF8362)],
      )),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Padding(
            padding: EdgeInsets.only(top: 2, right: 8),
            child: Opacity(
              opacity: 0.5,
              child: Text(
                "${widget.task.taskTypeStr}",
                style: TextStyle(
                    color: Colors.white,
                    fontSize: 22,
                    fontWeight: FontWeight.bold),
              ),
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              LoadAssetImage(
                Assets.homeLocation,
                width: 40,
              ),
              Expanded(
                child: Text(
                  "${widget.task.distance}km",
                  maxLines: 1,
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: 14,
                      fontWeight: FontWeight.bold),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  Widget _buildTaskRight() {
    return Padding(
      padding: EdgeInsets.only(top: 8, right: 8, bottom: 8),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "${widget.task.title}",
            style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
          ),
          Text(
            "${widget.task.address}",
            style: TextStyle(fontSize: 10, color: Color(0xFF909399)),
          ),
          Text(
            "${widget.task.createTime}",
            style: TextStyle(fontSize: 10, color: Color(0xFF909399)),
          ),
        ],
      ),
    );
  }
}
